﻿using System;
using Lucene.Net.Analysis;
using GermanAnalyzer = Lucene.Net.Analysis.De.GermanAnalyzer;
using System.Text;
using System.IO;

namespace OMC.DataManagement
{
    /// <summary>
    /// this class could use the lucene methods to analyze text
    /// </summary>
    /// <remarks>
    /// Copyright 2012 Stefan Lütolf
    /// Source: Hr.Martin Studer, HTW Chur
    /// </remarks>
    class LuceneAnalyzer
    {
        Analyzer TheAnalyzer;
        TokenStream TheTokenStream;
        StringBuilder TheStringBuilder;

        /// <summary>
        /// constructor of the LuceneAnalyzer
        /// </summary>
        public LuceneAnalyzer()
        {
            TheAnalyzer = new GermanAnalyzer();
            TheStringBuilder = new StringBuilder();
        }

        /// <summary>
        /// to analyzeString
        /// </summary>
        /// <param name="inString">the String to analyze</param>
        /// <returns>the analyzed String</returns>
        public String analyzeString(String inString)
        {
            TheTokenStream = TheAnalyzer.TokenStream(null, new StringReader(inString));

            while (TheTokenStream.IncrementToken())
            {
                String TheTempString = TheTokenStream.ToString();
                TheStringBuilder.AppendFormat("{0} ", TheTempString);
            }
            return TheStringBuilder.ToString();
        }
    }
}